package Exercise;

import static jdk.internal.icu.text.BidiBase.S;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-05-29
 * Time: 16:25
 */

/**
 * 字符串中的单词数
 */
class Solution {
    //方法1：有些特例过不了如：", , , ,        a, eaefa"
   /* public static boolean My_Character(char ch) {
        while (Character.isLetter(ch)) {
            return true;
        }
        return false;
    }
    public int countSegments(String s) {
        int number = 0;
        for (int i = 0; i < s.length(); i++) {
            if (My_Character(s.charAt(i))) {
                //注意split返回的是字符数组
                number = (s.split(" ")).length;
            }
        }

        return number;
}*/



//方法二
    /*public int countSegments(String s) {
        String[] arr = s.split(" ");
        int len = 0;
        for (String t : arr) {
        //isEmpty() 如果此列表不包含元素，则返回 true
            if (t.equals(" ") || t.isEmpty()){
                continue;
            }
            len++;
        }
        return len;
    }*/

}

